package com.yf1706.controller;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yf1706.dao.jpa.IFloatSalarySubsidyJDAO;
import com.yf1706.service.CountAbsenceDeductService;
import com.yf1706.service.SalaryDetailService;
import com.yf1706.vo.SalaryDetailVO;


@Controller
@RequestMapping("salary")
public class SalaryController {
	
	@Autowired
	CountAbsenceDeductService absenceDeductService;
	
	@Autowired
	private SalaryDetailService salaryDetailService;
	
	@RequestMapping("salary_home")
	public String salary_home() {
		return "djt/salary_home";
	}
	
	@RequestMapping("salary_sob")
	public String salary_sob() {
		return "djt/salary_sob";
	}
	
	@RequestMapping("salary")
	public String salary(String Sobid,HttpServletRequest request) {
		request.setAttribute("Sobid", Sobid);
		return "djt/salary";
	}
	
	@RequestMapping("salary_details")
	public String salary_details(String salaryId,HttpServletRequest request) {
		request.setAttribute("salaryId", salaryId);
		List<SalaryDetailVO> SalaryDetails = salaryDetailService.querySDAll(Integer.parseInt(salaryId));
		Map<Integer, List<SalaryDetailVO>> SalaryDetailsByEmpId =
				SalaryDetails.stream().collect(Collectors.groupingBy(SalaryDetailVO::getEmpId));
		int max=0;
		int len=0;
		for (List<SalaryDetailVO> value : SalaryDetailsByEmpId.values()) { 
			len = value.size();
			if (len > max) {
				max = len;
			}
		}
		request.setAttribute("maxLength", max);
		return "djt/salary_details";
	}
	
	@RequestMapping("base_salary_sob")
	public String base_salary_sob() {
		return "djt/base_salary_sob";
	}
	
	@RequestMapping("base_salary")
	public String base_salary(String Sobid,HttpServletRequest request) {
		request.setAttribute("Sobid", Sobid);
		return "djt/base_salary";
	}
	
	@RequestMapping("social_security_sob")
	public String social_security_sob() {
		return "djt/social_security_sob";
	}
	
	@RequestMapping("social_security")
	public String social_security(String Sobid,HttpServletRequest request) {
		request.setAttribute("Sobid", Sobid);
		return "djt/social_security";
	}
	@RequestMapping("social_security_type")
	public String social_security_type() {
		return "djt/social_security_type";
	}
	
	@RequestMapping("float_salary_sob")
	public String float_salary_sob() {
		return "djt/float_salary_sob";
	}
	
	@RequestMapping("float_salary")
	public String float_salary(String Sobid,HttpServletRequest request) {
		request.setAttribute("Sobid", Sobid);
		return "djt/float_salary";
	}
	
	@RequestMapping("float_salary_subsidy")
	public String float_salary_subsidy() {
		return "djt/float_salary_subsidy";
	}
	
	@RequestMapping("float_salary_performance")
	public String float_salary_performance() {
		return "djt/float_salary_performance";
	}
	
	@RequestMapping("float_salary_time_salary")
	public String float_salary_time_salary() {
		return "djt/float_salary_time_salary";
	}
	
	@RequestMapping("count_salary")
	public String count_salary() {
		return "djt/count_salary";
	}
	
	@RequestMapping("overtime_salary_rate")
	public String overtime_salary_rate() {
		return "djt/overtime_salary_rate";
	}
	
	@RequestMapping("absence_deduct")
	public String absence_deduct(HttpServletRequest request) {
		double Value = absenceDeductService.querySubsidyValue();
		request.setAttribute("SubsidyValue",Value );
		return "djt/absence_deduct";
	}
	
	@RequestMapping("income_tax_rates")
	public String income_tax_rates() {
		return "djt/income_tax_rates";
	}
	
}